package com.security.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.security.domain.CustomUserDetails;
import com.security.repository.UserRepository;

@Service
public class FitechUserDetailService implements UserDetailsService {

	@Autowired
	private UserRepository<CustomUserDetails> userRepository;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		System.out.println("========loadUserByUsername======"+username);
		CustomUserDetails userDetail = userRepository.findByUsername(username);
		return userDetail;
		
//		UserDetails user;
//		user = userRepository.findUserByUsername(username);
//		if (user != null) {
//			if (user.getUsername().equals("admin")) {
//			}
//			return user;
//		} else {
//			throw new UsernameNotFoundException(username);
//		}
	}

}
